/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tp_imag.gui.components;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;

/**
 *
 * @author gdenari
 */
public class JImagePanel extends JPanel {

     private BufferedImage image;
     int x, y;
     double sx, sy;

     public JImagePanel(BufferedImage image, int x, int y, Dimension size) {
         super();
         this.image = image;
         this.x = x;
         this.y = y;
         sx = size.width;
         sy = size.height;
     }

     public void setBufferedImage(BufferedImage image) {
         this.image = image;
     }

     @Override
     protected void paintComponent(Graphics g) {
         super.paintComponent(g);



         double xx = this.getParent().getSize().width;
         double yy = this.getParent().getSize().height;

         double nx = xx/sx;
         double ny = yy/sy;

         Graphics2D g2 = (Graphics2D)g;
         g2.scale(nx, ny);
         g2.drawImage(image, x, y, null);

         //g.drawImage(image, x, y, null);
     }



}